package cn.myjerry.test.reflection;

import java.lang.reflect.Method;

import cn.myjerry.test.reflection.bean.User;

@SuppressWarnings("all")
public class Demo04 {
	
	public static void test01() {
		User u = new User();
		long startTime = System.currentTimeMillis();
		for(int i=0;i<1000000000L;i++) {
			u.getName();
		}
		long endTime = System.currentTimeMillis();
		System.out.println("test01: => " + (endTime-startTime) + "ms");
	}

	public static void test02() throws Exception {
		User u = new User();
		Class<?> clazz = u.getClass();
		Method m = clazz.getDeclaredMethod("getName", null);
		long startTime = System.currentTimeMillis();
		for(int i=0;i<1000000000L;i++) {
			m.invoke(u, null);
		}
		long endTime = System.currentTimeMillis();
		System.out.println("test02: => " + (endTime-startTime) + "ms");
	}
	
	public static void test03() throws Exception {
		User u = new User();
		Class<?> clazz = u.getClass();
		Method m = clazz.getDeclaredMethod("getName", null);
		m.setAccessible(true);
		long startTime = System.currentTimeMillis();
		for(int i=0;i<1000000000L;i++) {
			m.invoke(u, null);
		}
		long endTime = System.currentTimeMillis();
		System.out.println("test03: => " + (endTime-startTime) + "ms");
	}
	
	public static void main(String[] args) throws Exception {
		test01();
		test02();
		test03();
	}
}
